package com.totoro.springcloud.hystrix_message.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.stereotype.Service;

/**
 * Created by Niki on 2018/5/2 8:17
 */
@Service
public class MessageService {
    private static int index = 0 ;
    @HystrixCommand(
            fallbackMethod = "sendMessageSecondary",
            commandProperties = {
                    @HystrixProperty(
                            name = "execution.isolation.thread.timeoutInMilliseconds",
                            value = "1000" //熔断器打开到关闭的时间窗口
                    )
//                    ,
//                    @HystrixProperty(
//                            name = "",
//                            value=""
//                    )
            },
            threadPoolProperties = {
                    @HystrixProperty(
                            name = "coreSize",
                            value = "5"
                    ),
                    @HystrixProperty(
                            name = "maximumSize",
                            value = "10"
                    ),
                    @HystrixProperty(
                            name = "allowMaximumSizeToDivergeFromCoreSize",
                            value = "true"
                    )
            }
    )
    public void sendMessagePrimary(String message) {
        if(index >50 && index < 100){
            throw new RuntimeException("供应商一接口异常！");
        }
        System.out.println("**********短信供应商**********"+index);
        index++ ;
    }

    public void sendMessageSecondary(String messagePush) {
        System.out.println("**********极光推送**********"+index);
        index++ ;
    }
}
